package mysql

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);unique;comment:手机号"`
	Password string `gorm:"type:char(32);comment:密码"`
	RealName string `gorm:"type:char(3);comment:姓名"`
	IDCord   string `gorm:"type:char(18);comment:身份证号码"`
	Front    string `gorm:"type:varchar(300);comment:正面身份证"`
	Back     string `gorm:"type:varchar(300);comment:反面身份证"`
	Status   int64  `gorm:"type:tinyint(1);default:1;comment:状态:1:待审核,2:审核通过,3:审核未通过"`
}

func (u *User) Create() error {
	return Db.Create(&u).Error
}

func (u *User) UserInfo(mobile string) error {
	return Db.Where("mobile = ?", mobile).Limit(1).Find(&u).Error
}
func (u *User) UpdateRealName() error {
	return Db.Where("id = ?", u.ID).Updates(&User{RealName: u.RealName, IDCord: u.IDCord,
		Front: u.Front, Back: u.Back}).Limit(10).Find(&u).Error
}
func (u *User) UpdateUser(userId int64, status int64) error {
	return Db.Model(&User{}).Where("id = ?", userId).Update("status", status).Limit(2).Find(&u).Error
}
